//
//  QuchongHeaderView.m
//  DocOpretionDemo
//
//  Created by haoxiang on 17/9/9.
//  Copyright © 2017年 youyixinxi. All rights reserved.
//

#import "QuchongHeaderView.h"

#define Screen_width           [UIScreen mainScreen].bounds.size.width
#define Screen_height          [UIScreen mainScreen].bounds.size.height

@interface QuchongHeaderView (){

    NSInteger     _sectionNum;
}

@property (nonatomic,strong) UILabel            *titleName;
@property (nonatomic,strong) UILabel            *ifFree;
@property (nonatomic,strong) UILabel            *remarkText;
@property (nonatomic,strong) UISwitch           *switchV;

@end

@implementation QuchongHeaderView

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier{

    self = [super initWithReuseIdentifier:reuseIdentifier];
    if (self) {
        [self setUI];
    }
    return self;
}

- (void)sectionNumber:(NSInteger)number{

    _sectionNum = number;
}

- (void)setUI{
    
    self.contentView.backgroundColor = [UIColor whiteColor];
    
    _titleName = [[UILabel alloc]initWithFrame:CGRectMake(20, 13, 70, 20)];
    _titleName.backgroundColor = [UIColor clearColor];
    _titleName.textColor = [UIColor blackColor];
    _titleName.font = [UIFont systemFontOfSize:15];
    [self.contentView addSubview:_titleName];
    
    _ifFree = [[UILabel alloc]initWithFrame:CGRectMake(_titleName.frame.origin.x+_titleName.frame.size.width, _titleName.frame.origin.y+_titleName.frame.size.height - 17, 25, 15)];
    _ifFree.textColor = [UIColor whiteColor];
    _ifFree.font = [UIFont systemFontOfSize:11];
    _ifFree.layer.cornerRadius = 2;
    _ifFree.layer.masksToBounds = YES;
    _ifFree.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:_ifFree];
    
    _remarkText = [[UILabel alloc]initWithFrame:CGRectMake(_titleName.frame.origin.x, _titleName.frame.origin.y+_titleName.frame.size.height, Radio*280, 20)];
    _remarkText.backgroundColor = [UIColor clearColor];
    _remarkText.textColor = [UIColor lightGrayColor];
    _remarkText.font = [UIFont systemFontOfSize:13];
    [self.contentView addSubview:_remarkText];
    
    _switchV = [[UISwitch alloc]initWithFrame:CGRectMake(Screen_width-70, 17, 100, 28)];
    _switchV.on = YES;
    _switchV.onTintColor = mainColor;
    [_switchV addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged];
    [self.contentView addSubview: _switchV];

}

-(void)switchAction:(id)sender
{
    UISwitch *switchButton = (UISwitch*)sender;
    BOOL isButtonOn = [switchButton isOn];
    if ([self.delegate respondsToSelector:@selector(switchValueYesOrNo:sectionNum:)]) {
        [self.delegate switchValueYesOrNo:isButtonOn sectionNum:_sectionNum];
    }
}

@end
